<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './resize'
  import { req } from '../../../api/base/BaseApi'
  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '390px'
      }
    },
    data() {
      return {
        damData: [],
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        // this.getChartData()
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      getChartData() {
        req('/api/sys/auth/monitor/acoustic_emission', 'POST', '').then(response => {
          this.damData = response.data
          this.chart.hideLoading()
        }).catch(() => console.log('page request error'))
      },
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.showLoading()
        this.getChartData()
        this.chart.setOption({
          title: {
            text: '疲劳损伤',
            x: 'center'
          },
          // legend: {
          //
          // },
          // color: ['#3398DB'],
          tooltip: {
            // trigger: 'axis',
            // axisPointer: {
            //   type: 'shadow'
            // }
          },

          series: [
            {
              min: 0,
              max: 1,
              name: '损伤值',
              type: 'gauge',
              detail: null,
              // barWidth: '60%',
              data: [0.3, 0.2, 0.1, 0.05, 0.1, 0.3, 0.5, 0.7]
              // data: [0.3]
            }
          ]
        })
      }
    }
  }
</script>
